// ----------
//  BASE LIB
// ----------

// returns result of xpath query
function getElementSnapshots(xpathExp)
{
    return document.evaluate(
        xpathExp,
        document,
        null,
        XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
        null);
}

// returns result of xpath query below a given node
function getElementSnapshotsFromContext(contextNode, xpathExp)
{
	return document.evaluate(
        xpathExp,
        contextNode,
        null,
        XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
        null);
}

// returns a single dom element by xpath expression
function getElement(xpathExp)
{
    return getElementSnapshots(xpathExp).snapshotItem(0);
}

function elementExists(xpathExp)
{
    return (getElement(xpathExp) != null);
}

function replaceElement(oldElement, newElement){

    oldElement.parentNode.insertBefore(newElement, oldElement);
    
    // remove original table 
    oldElement.parentNode.removeChild(oldElement);
}